package cumeo89.chii.client.entry.renderer;

import static cumeo89.chii.client.entry.Constants.*;

import com.google.gwt.xml.client.Attr;
import com.google.gwt.xml.client.Node;

import cumeo89.chii.client.entry.AbstractRenderer;
import cumeo89.chii.client.ui.TrivialPanel;
import cumeo89.chii.client.util.MyArrays;
import cumeo89.chii.client.util.XMLUtil;

public class CodeRenderer extends AbstractRenderer {

	private TrivialPanel text;

	public CodeRenderer() {
		text = new TrivialPanel("span");
		text.setStyleName("code");
		initWidget(text);
	}

	@Override
	public void prepareWidget(Node node, boolean selected) {
		super.prepareWidget(node, selected);
		String tag = XMLUtil.getElement((Attr) node).getTagName();
		String code = ((Attr) node).getValue();
		text.setTitle("{{-" + code + "-}}");

		String name = "&lt;không rõ&gt;";
		if (E_LANG.equals(tag)) {
			name = MyArrays.translate(code, getLanguageCodes(),
					getLanguageNames());
		} else if (E_POS.equals(tag)) {
			name = MyArrays.translate(code, getPosCodes(), getPosNames());
		} else {
			name = MyArrays.translate(code, RELATED_WORDS_CODES,
					RELATED_WORDS_NAMES);
		}
		text.setHTML(name);
	}

}
